<?php

/**
 * @author Dileesh Meladath
 * @copyright 2011
 */
 
    include_once("../includes/appdata.php");
    require_once(APP_DIRECTORY."/php/include.php");
    
    spl_autoload_register('__autoload');
    
    $lblMgr = new LabelManager();
    
    if(isset($_GET["page"]) && $_GET["page"] != "")
		$page_no = $_GET["page"];
	else
		$page_no = 1;
	$size = LIST_ITEMS_PER_PAGE;
    
    $count = $lblMgr->getLabelCount();
    
    $num_pages = ceil($count / $size);
    
    //echo $count; exit;
    
    $labelList = $lblMgr->getLabelsList( $page_no-1, $size );
    //printObject($labelList);
    //exit;
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>PowerMan - Page Title</title>
        <link rel="shortcut icon" href="<?php echo ROOT_DIR; ?>favicon.ico" type="image/x-icon" />
        
        <link rel="stylesheet" href="<?php echo ROOT_DIR; ?>css/common.css" type="text/css" media="screen" title="default" />
        <link rel="stylesheet" href="<?php echo ROOT_DIR; ?>css/main.css" type="text/css" media="screen" title="default" />
        <link rel="stylesheet" href="<?php echo ROOT_DIR; ?>css/form.css" type="text/css" media="screen" title="default" />
        <link rel="stylesheet" href="<?php echo ROOT_DIR; ?>css/tabing.css" type="text/css" media="screen" title="default" />
        <link rel="stylesheet" href="<?php echo ROOT_DIR; ?>css/jquery.autocomplete.css" type="text/css" media="screen" title="default" />
        
        <!--[if IE]>
        <link rel="stylesheet" media="all" type="text/css" href="css/ie.css" />
        <![endif]-->
        
        <!--  jquery core & library -->
        <script src="<?php echo ROOT_DIR; ?>js/jquery-1.5.2.min.js" type="text/javascript"></script>
        <script src="<?php echo ROOT_DIR; ?>js/jquery.validate.js" type="text/javascript"></script>
        <script src="<?php echo ROOT_DIR; ?>js/jquery.autocomplete.js" type="text/javascript" ></script>
        <script src="<?php echo ROOT_DIR; ?>js/additional-methods.js" type="text/javascript"></script>
        <script src="<?php echo ROOT_DIR; ?>js/jquery.validate.messages.js" type="text/javascript"></script>
        <link type="text/css" href="<?php echo ROOT_DIR; ?>css/ui-darkness/jquery-ui-1.8.7.custom.css" rel="stylesheet" />	
		<script type="text/javascript" src="<?php echo ROOT_DIR; ?>js/jquery-ui-1.8.7.custom.js"></script>
        
        <!--  styled file upload script --> 
        <script src="<?php echo ROOT_DIR; ?>js/jquery.filestyle.js" type="text/javascript"></script>
        
        <script src="<?php echo ROOT_DIR; ?>js/lib.js" type="text/javascript"></script>
        <script src="<?php echo ROOT_DIR; ?>js/powerman.js" type="text/javascript"></script>
    </head>
    <body>   
        <script language="javascript">
        function edit(LabelID){
            $("#elabelid").val(LabelID);
            $("#frmEdit").submit();
        }        
    </script> 
        <!-- start content-outer -->
        <div id="content-outer">
            <!-- start content -->
            <div id="content">
                <div id="page-heading"><h1>Add Label</h1></div>
        
                <table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
                    <tr>
                        <th rowspan="3" class="sized">
                            <img src="<?php echo ROOT_DIR; ?>images/side_shadowleft.jpg" width="20" height="300" alt="" />
                        </th>
                        <th class="topleft"></th>
                        <td id="tbl-border-top">&nbsp;</td>
                        <th class="topright"></th>
                        <th rowspan="3" class="sized">
        
                            <img src="<?php echo ROOT_DIR; ?>images/side_shadowright.jpg" width="20" height="300" alt="" />
                        </th>
                    </tr>
                    <tr>
                        <td id="tbl-border-left"></td>
                        <td>
        
        <!--  start content-table-inner -->
        <div id="content-table-inner">
            <!--  start table-content  -->
        
        	<div id="table-content">
                </div>
            
            <table>
        	<tr  class="h0">
        		<td width="25"></td>
        		<td>Name</td>        		
        		<td colspan="2">
                    <div style="display: none;">
                        <form id="frmEdit" method="POST" action="editlabel.php">
                            <input type="hidden" id="elabelid" name="labelid" value="" />
                            <input type="hidden" name="from" value="list" />
                        </form>                        
                    </div>
                </td>
        	</tr>
        	<?php
        		$i = ($page_no-1)*$size + 1;
        		foreach( $labelList as $label  ) {
        	?>
        	<tr>
        		<td><?php echo $i; ?></td>
        		<td><?php echo $label["name"]; ?></td>
        		<td style="width:30px">
                
                <input type="button" value="" class="form-edit" onclick='edit(<?php echo $label["Id"]; ?>)' />
        		
        		</td>        		
        	</tr>
        	<?php
        		$i++;
        		}
        	?>
        	<tr>
        		<td colspan="11">
        			<div style="float:right">
        				<?php
        					if($num_pages>1) {
        				?>
        					Page:
        					<select ONCHANGE="location = 'listlabels.php?page=' + this.options[this.selectedIndex].value;" class="page-select">
        						<?php
        							for( $k=1; $k<=$num_pages; $k++) {
        						?>
        							<option value="<?php echo $k; ?>" <?php if($k==$page_no) echo "selected";?>>
        								<?php echo $k; ?>
        							</option>
        						<?php
        							}
        						?>	
        					</select>
        				<?php
        					}
        				?>
        			</div>
        		</td>
        	</tr>
        	
        </table>  
            </div>
        
        </div>
<!--  end content-outer -->
        
        
        <div class="clear">&nbsp;</div>


        <!-- start footer -->         
        <div id="footer">
        	<!--  start footer-left -->
        	<div id="footer-left">
        	PowerMan &copy; Copyright. All rights reserved.</div>

        	<!--  end footer-left -->
        	<div class="clear">&nbsp;</div>
        </div>
        <!-- end footer -->
        
    </body>
  </html>